package com.czollmann.android;

import org.joda.time.DateTime;

public class ObjectWrapper implements Comparable {
  protected DateTime date;
  private SMSObject smsObject = null;
  private CallObject callObject = null;
  private ImageObject imageObject = null;

  public ObjectWrapper(DateTime date, CallObject callObject) {
    this.date = date;
    this.callObject = callObject;
  }

  public ObjectWrapper(Long date, CallObject callObject) {
    this.date = new DateTime().withMillis(date);
    this.callObject = callObject;
  }

  public ObjectWrapper(Long date, ImageObject imageObject) {
    this.date = new DateTime().withMillis(date);
    this.imageObject = imageObject;
  }

  public ObjectWrapper(DateTime date, SMSObject smsObject) {
    this.date = date;
    this.smsObject = smsObject;
  }

  public ObjectWrapper(Long date, SMSObject smsObject) {
    this.date = new DateTime().withMillis(date);
    this.smsObject = smsObject;
  }

  public DateTime getDate() {
    return date;
  }

  public void setDate(DateTime date) {
    this.date = date;
  }

  public SMSObject getSmsObject() {
    return smsObject;
  }

  public void setSmsObject(SMSObject smsObject) {
    this.smsObject = smsObject;
  }

  public CallObject getCallObject() {
    return callObject;
  }

  public void setCallObject(CallObject callObject) {
    this.callObject = callObject;
  }

  public ImageObject getImageObject() {
    return imageObject;
  }

  public void setImageObject(ImageObject imageObject) {
    this.imageObject = imageObject;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj instanceof ObjectWrapper) {
      ObjectWrapper objectWrapper = (ObjectWrapper) obj;
      if (objectWrapper.getCallObject() != null) {
        if (getCallObject() != null) {
          if (objectWrapper.getDate().equals(getDate())) {
            return true;
          }
        }
      } else if (objectWrapper.getSmsObject() != null) {
        if (getSmsObject() != null) {
          if (objectWrapper.getDate().equals(getDate())) {
            return true;
          }
        }
      } else if (objectWrapper.getImageObject() != null) {
        if (getImageObject() != null) {
          if (objectWrapper.getImageObject().equals(getImageObject())) {
            return true;
          }
        }
      }
      return false;
    }
    return super.equals(obj);
  }

  public int compareTo(Object obj) {
    if (obj instanceof ObjectWrapper) {
      if (this.date.isBefore(((ObjectWrapper) obj).getDate()))
        return 1;
      else if (this.date.isAfter(((ObjectWrapper) obj).getDate()))
        return -1;
    }
    return 0;
  }

  @Override
  public String toString() {
    return "ObjectWrapper ["
              + (callObject != null ? "callObject=" + callObject + ", " : "")
              + (date != null ? "date=" + date + ", " : "")
              + (imageObject != null ? "imageObject=" + imageObject + ", " : "")
              + (smsObject != null ? "smsObject=" + smsObject : "") + "]";
  }
}
